package com.atguigu.gmall.realtime.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author lzc
 * @Date 2022/4/19 14:31
 */
public class RedisUtil {
    private static JedisPool pool;
    
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(300);
        config.setMaxIdle(10);
        config.setMinIdle(2);
        
        config.setTestOnCreate(true);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        
        
        config.setMaxWaitMillis(10 * 1000);
        
        pool = new JedisPool(config, "hadoop162");
        
    }
    
    
    public static Jedis getRedisClient() {
        Jedis resource = pool.getResource();
        resource.select(1);  // 给jedis客户端选择默认的数据库
        return resource;
    }
    
}
